package robot;

import java.io.IOException;
import robot.devices.All;
import robot.devices.Battery;
import robot.devices.Led;
import robot.devices.Telemeters;
import robot.devices.Wheels;
import robot.devices.Telemeters.IR_MODE;
import robot.exception.RobotException;
import robot.protocol.DATA_DESCRIPTOR;
import robot.utils.ConnectionRobot;

public class Robot {

	private String name;

	
	private Telemeters telemeters;
	private Wheels wheels;
	private Battery battery;
	private Led led;
	private All all;

	public ConnectionRobot connection;


	public Robot(String name) throws IOException, RobotException {
		// TODO Auto-generated constructor stub
		super();
		this.name = name;
		this.connection = new ConnectionRobot(name);
//		this.connection.resetRobot();
		this.all = new All(this);
//		this.all.setTimeout();
		
		this.telemeters = new Telemeters(this);
		this.getTelemeters().setMode(IR_MODE.IR_MODE_SHORT);
		this.wheels = new Wheels(this);
		this.battery = new Battery(this);
		this.led = new Led(this);
	}

	public void displayAllInformation() throws RobotException {
		byte[] data = this.all.getAll();

		for (int i = 0; i < data.length; i++) {
			System.out.println ("Adress 0x" + Integer.toHexString(i + DATA_DESCRIPTOR.IR_ON_OFF.getValue()) + " = 0x" +
					Integer.toHexString(data[i]));
		}
	}
	

	public byte[] getAllInformation() throws RobotException {
		byte[] data = this.all.getAll();

		return data;
	}


	public String getName() {
		return name;
	}

	public Telemeters getTelemeters() {
		return telemeters;
	}

	public Wheels getWheels() {
		return wheels;
	}
	
	public Led getLed() {
		return led;
	}
	
	public Battery getBattery() {
		return battery;
	}



}
